<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    用户名<input type="text" class="a"> <br>
    手机号 <input type="text" class="b"> <br>
    邮箱 <input type="text" class="c"> <br>
    密码 <input type="text" class="d"> 
    <button>注册</button>

    <script src="../js/tools.js"></script>

    <script>

        getEle('button').onclick = function() {
            const uname = getEle('.a').value;
            const utel = getEle('.b').value;
            const uemail = getEle('.c').value;
            const upwd = getEle('.d').value;

            if(uname && upwd && utel && uemail) {
                // const userObj = {
                //     uname : uname ,
                //     upwd : upwd , 
                //     uemail : uemail
                // } ;

                // 简写   对象中，键名和键值一样可以使用简写
                const userObj = {
                    uname ,
                    upwd , 
                    uemail 
                } ;

                // 手机号作为唯一字段
                const res = localStorage.getItem('QWERT__' + utel) ;

                if(res) {
                    alert('已被注册')
                } else {
                    alert('注册成功')
                    localStorage.setItem('QWERT__' + utel , JSON.stringify(userObj)) ;
                }         
               
            }
        }

    </script>
    
</body>
</html>